package com.wuneng.ircontrol.myUtil.common;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.wuneng.ircontrol.common.util.Constants;

public class LogUtil {

    public static void write(String text) {

        SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyy-MM-dd");
        Date curDate = new Date(System.currentTimeMillis());
        String rightTime = dateformat1.format(curDate);
        File file = new File(Constants.FILE_PATH.LOG_PATH + "/" + rightTime + ".txt");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            StringBuffer buffer = new StringBuffer();
            FileWriter fw;
            fw = new FileWriter(file, true);
            fw.flush();
            fw.write("\n" + getTime() + " " + text);
            fw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static String getTime() {
        DateFormat df = new SimpleDateFormat("HH:mm:ss");
        Date date1 = new Date(System.currentTimeMillis());
        return df.format(date1);

    }
}
